package com.bf.hotpoint.repository.redis;

import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundHashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Repository;

import com.bf.hotpoint.domain.User;
import com.bf.hotpoint.enums.RedisKeyEnum;

@Repository
public class UserRedisRepository {
	
	@Autowired
	private RedisTemplate<String, User> redisTemplate;
	
	public void setUsers(Map<String, User> users,Date expireAt)
	{
		BoundHashOperations<String, String, User> boundHashOps = redisTemplate.boundHashOps(RedisKeyEnum.USER.getKey());
		boundHashOps.putAll(users);
	}
	
	public void setUser(User user,Date expireAt)
	{
		BoundHashOperations<String, String, User> boundHashOps = redisTemplate.boundHashOps(RedisKeyEnum.USER.getKey());
		if(user != null)
		{
			boundHashOps.put(user.getUuid(), user);
		}
	}
	
	public User getUserByUuid(String uuid)
	{
		BoundHashOperations<String, String, User> boundHashOps = redisTemplate.boundHashOps(RedisKeyEnum.USER.getKey());
		return boundHashOps.get(uuid);
	}
}
